﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace FigureDraw
{
    public enum PenType{Thin, Medium, Large}
    public enum DiagramType { BasicShape, FlowChart, DataFlow, Activities}
    public enum DiagramTep { Start, Stop}

    public partial class Form1 : Form
    {
        public Target myTarget;
        private bool flagPaint;

        private Vector2 oldPosition;
        private Vector2 curPosition;
        private ArrayList myShapes;

        private Paper paper;

        public Form1()
        {
            InitializeComponent();
            myInit();
        }

        private void myInit()
        {
            flagPaint = false;
            oldPosition = new Vector2();
            curPosition = new Vector2();
            myShapes = new ArrayList();
            paper = new myScreen(this);
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Drawing.Graphics g1 = this.CreateGraphics();
            g1.Clear(this.BackColor);
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        

        private string filePath="";
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.InitialDirectory = Convert.ToString(Environment.SpecialFolder.MyDocuments);
            saveFileDialog1.Filter = "PNG (*.png)|*.png|JPEG (*.jpg)|*.ext";
            saveFileDialog1.FilterIndex = 1;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Console.WriteLine(saveFileDialog1.FileName);//Do what you want here
                filePath = saveFileDialog1.FileName;
                myTarget.SavePNG(filePath);
            } 
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            flagPaint = true;
            oldPosition.X = e.Location.X;
            oldPosition.Y = e.Location.Y;
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            curPosition.X = e.Location.X;
            curPosition.Y = e.Location.Y;
            if (radioButtonGDIPlus.Checked)
            {
                myTarget = new GDIPlusAdapter();
            }
            else
            {
                myTarget = new CairoAdapter();
            }

            myShape eclipseShape = new myEclipse(oldPosition, curPosition);
            eclipseShape.Draw(myTarget, paper, PenType.Thin);
            myShapes.Add(eclipseShape);
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            for (int i = 0; i < myShapes.Count; i++)
            {
                myShape m = (myShape)myShapes[i];
                m.Draw(myTarget, paper, PenType.Thin);
            }

            //Graphics myGraphics = e.Graphics;
            //Pen myPen = new Pen(Color.Black);
            //Point p1 = new Point(0,0);
            //Point p2 = new Point(1000, 1000);
            //myGraphics.DrawLine(myPen, p1, p2);
        }
    }
}
